package com.mongo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;


public abstract class AbstractMongoQuery<T> {

	@Autowired
	MongoTemplate mongoTemplate;
	
	
	protected abstract Class<T> entityClass();
	
	public  T findByUrl(String url,String collectionName){
		Query query=new Query(Criteria.where("shortUrl").is(url));
		return mongoTemplate.findOne(query, this.entityClass(),collectionName);
	}
	
	public void insert(T t,String collectionName){
		mongoTemplate.insert(t, collectionName);
	}
	
}
